<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>{{ pointTime }}当天职工餐评</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div class="food-body" v-if="tableList.length">
          <div class="food-list" v-for="(item,index) in tableList" :key="index">
            <h3 class="food-list-title">{{ item.food }}</h3>
            <div class="point-user-status">
              <div class="point-user-status-list">
                已点评<i>{{ item.user.length }}</i>人
              </div>
              <div class="point-user-status-list" @click="getFoodListFn(item.user)">
                未点评<i>{{ userList.length - item.user.length }}</i>人
              </div>
            </div>
            <el-table
                :data="item.user"
                stripe
                size="mini">
              <el-table-column
                  prop="realname"
                  :label="`姓名(${item.user.length})`"
                  width="70"
                  align="center">
              </el-table-column>
              <el-table-column
                  prop="address"
                  :label="`喜欢(${item.goods_number})`"
                  width="80"
                  align="center">
                <template slot-scope="scope">
                  {{ Number(scope.row.type) == 1 ? '✓' : '' }}
                </template>
              </el-table-column>
              <el-table-column
                  prop="address"
                  :label="`不喜欢(${item.bad_number})`"
                  width="80"
                  align="center">
                <template slot-scope="scope">
                  {{ Number(scope.row.type) == 2 ? '✓' : '' }}
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div v-else class="not-data-point">
          未找到当天相关点评内容
        </div>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
      </div>
    </div>
    <food_not_common :visible.sync="comonVisible" :userlist="userList" :commonlist="optionList"></food_not_common>
  </div>
</template>

<script>
import {todayComment} from '@/api/admin/food'
import {tearchUserAll} from '@/api/admin/users.js'
import food_not_common from "@/views/admin/dayWork/components/food_not_common";

export default {
  props: ['visible', 'pointTime'], // recruitmentType examine 审核
  components: {food_not_common},
  data() {
    return {
      dialogVisible: false,
      tableList: [],
      userList: [],
      optionList: [],
      comonVisible: false
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.getAlltearchFn()
        this.getWeekFood()
      } else {
        this.tableList = []
        this.userList = []
        this.optionList = []
      }
    }
  },
  created() {
  },
  methods: {
    getAlltearchFn() {
      tearchUserAll().then(res => {
        console.log('全部用户user_res:', res)
        this.userList = res.list
        // 比对未点评的人员

      })
    },
    getWeekFood() {
      todayComment({time: this.pointTime}).then(res => {
        this.tableList = res.list
      })
    },
    getFoodListFn(option){
      this.optionList = JSON.parse(JSON.stringify(option))
      this.comonVisible = true
    },
    showInput(index) {
      let option = this.arryList[index];
      option.visible = true
      this.$set(this.arryList, index, option)
      this.$nextTick(_ => {
        this.$refs.saveTagInput.$refs.input.focus();
      });
    },
    saveFoodInput(index) {
      let option = this.arryList[index]
      console.log('option:', option)
      teachFoodWeekAdd({create_time: option.day, name: option.newFood.join(',')}).then(res => {
        console.log('res:', res)
        if (!res.code) {
          this.$message.success('保存成功！')
          this.getWeekFood()
        }
      })
    },
    handleInputConfirm(index) {
      let inputValue = this.inputValue;
      let option = this.arryList[index]
      if (inputValue) {
        option.newFood.push(inputValue)
      }
      this.inputValue = '';
      option.visible = false;
      this.$set(this.arryList, index, option)
    },
    handleClose(line, index) {
      let that = this
      this.$confirm('删除当天餐品, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        that.weekFoodDeletFn(line, index)
      }).catch(() => {
      })
    },
    handleNewClose(line, index) {
      let option = this.arryList[line]
      option.newFood.splice(index, 1)
      this.$set(this.arryList, line, option)
    },
    weekFoodDeletFn(line, index) {
      let option = this.arryList[line]
      console.log('detel:', index)
      teachFoodWeekDelete({id: option.list[index].id}).then(res => {
        if (!res.code) {
          this.$message.success('删除成功！')
          option.list.splice(index, 1)
          this.$set(this.arryList, line, option)
        }
      });
    },
    checkEditFn() {
      if (!this.infoForm.name) {
        this.$message.error('请填写餐品名称');
        return
      }
      if (!this.foodOption) {
        teachFoodAdd({name: this.infoForm.name}).then(res => {
          console.log(res)
          if (!res.code) {
            this.$message.success(res.msg)
            this.$emit('initPage')
            this.closePOpup()
          } else {
            this.$message.error(res.msg)
          }
        })
      } else {
        teachFoodEdit({name: this.infoForm.name, id: this.foodOption.id}).then(res => {
          if (!res.code) {
            this.$message.success(res.msg)
            this.$emit('initPage')
            this.closePOpup()
          } else {
            this.$message.error(res.msg)
          }
        })
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  /*width: 950px;*/
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  max-height: 650px;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}

.food-body {
  /*display: flex;*/
}

.food-list {
  border: 1px solid #cacaca;
  margin-right: 5px;
  border-radius: 5px;
  overflow: hidden;
  box-shadow: 0 2px 2px #c5c5c5;
  /*flex: 1;*/
  width: 232px;
  display: table-cell;
}

.food-list:last-child {
  margin-right: 0;
}

.food-list-title {
  background: #1b8de5;
  height: 30px;
  line-height: 30px;
  text-align: center;
  color: #fff;
}

.not-data-point {
  width: 400px;
  height: 400px;
  line-height: 400px;
  text-align: center;
  color: #999;
}

.point-user-status {
  display: flex;
  align-items: center;
  background: #eee;
}

.point-user-status-list {
  flex: 1;
  text-align: center;
  height: 30px;
  line-height: 30px;
  cursor: pointer;
}

.point-user-status-list i {
  margin: 0 3px;
  color: #ef6f14;
  font-size: 16px;
  font-weight: bold;
  font-style: normal;
}

.point-user-status-list:first-child {
  border-right: 1px solid #ddd;
}
</style>
